package com.darrenchan.netease03

/**
  * 混入
  */

//顶级接口
trait Mylogger {
  //具体方法
  def log(msg: String){}
}

//旧实现
trait Logger_A extends Mylogger {
  override def log(msg: String): Unit = {
    println("AAAA：" + msg)
  }
}

//新实现
trait Logger_B extends Mylogger {
  override def log(msg: String): Unit = {
    println("BBBB：" + msg)
  }
}


class Logger_Son(val name: String) extends Logger_A {
  def sayHello() = {
    println("hi, xxxx")
    log("sayHello is invoked!")
  }
}

object Trait_Mixins {
  def main(args: Array[String]): Unit = {
    /**
      * hi, xxxx
      * AAAA：sayHello is invoked!
      */
    val ll = new Logger_Son("chenchi")
    ll.sayHello()

    /**
      * hi, xxxx
      * BBBB：sayHello is invoked!
      *
      *
      * 这个语法的目的就是，在原有代码不修改的基础上，实现新的功能
      */
    val ll2 = new Logger_Son("shizetao") with Logger_B
    ll2.sayHello()
  }
}
